home *** CD-ROM | disk | FTP | other *** search
- /*
- GetTLE - Util.c - two routines to make fields less complicated
- Copyright ⌐2000 Andreas Schneider
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
- #include <PalmOS.h>
- #include "Util.h"
-
- // Set the text of a field to the text given by NewHandle
- // also free the OldHandle (if any)
- extern FieldPtr SetFormFieldTextFromHandle(FormPtr Form,UInt16 FieldID, MemHandle NewHandle)
- {
- MemHandle OldHandle;
- FieldPtr Field;
-
- // get the field and it's text VoidHand.
- Field = FrmGetObjectPtr(Form, FrmGetObjectIndex(Form, FieldID));
- if (Field)
- {
- // remember the old handle - we might have to free it later
- OldHandle = (MemHandle) FldGetTextHandle(Field);
- // set the field's text to the new text
- FldSetTextHandle(Field, (MemHandle) NewHandle);
- // redraw the field to make the change visible
- FldDrawField(Field);
- // now that the field has the new handle we should free the old one
- if (OldHandle)
- {
- MemHandleFree(OldHandle);
- }
- }
- return Field;
- }
-
- // even more coveniant: just pass the text - the Handle stuff
- // is handled by this routine - this one needs the FormPtr
- extern FieldPtr SetFormFieldTextFromString(FormPtr Form,UInt16 FieldID, Char *String)
- {
- MemHandle NewHandle;
- FieldPtr Field=NULL;
-
- // allocate memory for a copy of the string plus trailing \0
- NewHandle = MemHandleNew(StrLen(String) + 1);
- if (NewHandle)
- {
- // lock the handle and copy the string to it
- StrCopy(MemHandleLock(NewHandle), String);
- // unlock the handle
- MemHandleUnlock(NewHandle);
- // set the field text using the above routine
- Field = SetFormFieldTextFromHandle(Form,FieldID,NewHandle);
- }
- return Field;
- }
-
-
- // we might not want to specify the Form
- extern FieldPtr SetFieldTextFromString(UInt16 FieldID,Char *String)
- {
- FieldPtr Field;
-
- Field=SetFormFieldTextFromString(FrmGetActiveForm(),FieldID,String);
- return Field;
- }